package com.chang.spring6.iocXML.bean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestUserDao {
    public static Logger logger = LoggerFactory.getLogger(TestUserDao.class);

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("bean.xml");
        // 如果组件类实现了接口，可以根据接口类型可以获取 bean(接口实现类) 但是前提必须是bean唯一 也就是说必须只有一个接口实现类
        //UserDaoImpl userDao = context.getBean(UserDaoImpl.class);

        // 如果有多个接口实现类可以通过id获取bean然后再强转
        UserDao userDao = (UserDao) context.getBean("userDaoImpl2");
        logger.info("userDao创建完成>>");
        System.out.println(userDao);
        userDao.run();
    }
}
